#!/bin/bash


WORK_PATH="/opt/middleware/AtlasEdge"
SCRIPT_PATH="/opt/middleware/AtlasEdge/software/edge_site/edge_manager/src/script"

. ${SCRIPT_PATH}/common.sh
. ${SCRIPT_PATH}/log_util.sh

ATLASEDGE_UPDATE_WORKKEY="${WORK_PATH}/software/bin/update_workkey"
ATLASEDGE_CORE_CONFIG_FILE="${WORK_PATH}/software/edge_core/conf/edgecore.yaml"

main()
{
    in_pWord=`grep cloudpword ${ATLASEDGE_CORE_CONFIG_FILE} | sed 's/.*cloudpword: //g'`
    if [ -z ${in_pWord} ]; then
        logger_Warn "get encrpyt failed!"
        return -1
    fi

    out_pWord=`${WORK_PATH}/software/libs/ld-linux-aarch64.so.1 --library-path ${WORK_PATH}/software/libs/ ${ATLASEDGE_UPDATE_WORKKEY} 1 ${in_pWord}`
    ret=$?
    if [ ${ret} != 0 ]; then
        logger_Warn "update pWord set failed "
        return -1
    fi
    sed -i "s|cloudpword:.*|cloudpword: ${out_pWord}|g" ${ATLASEDGE_CORE_CONFIG_FILE}

    echo "out_pWord are: $out_pWord"
}

main "$@"
RESULT=$?
echo "ret:$RESULT"

exit $RESULT
